home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
C-H
/
CHexDmpDA.cpt
/
Hex Dump DA
/
goto.HexDumpDA.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-14
|
2KB
|
138 lines
#include <DialogMgr.h>
#include "HexDump.h"
static long gotoPoint;
static DialogPtr dp;
extern long sBegin;
extern long fileSize;
doGoto()
{
if (Conduct_Goto_Dialog()) {
New_Select(gotoPoint, gotoPoint+1);
Show_Point(gotoPoint);
}
}
/* Goto Dialog Items: */
#define OK 1
#define CANCEL 2
#define GOTOSTRING 3
pascal Boolean Hex_Digit_Filter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
int *itemHit;
{
char theChar;
if (theEvent->what==keyDown) {
theChar = theEvent->message & charCodeMask;
if ((theChar==0x03) || (theChar==0x0D)) {
*itemHit = 1;
return true;
}
else if (((theChar>='0') && (theChar<='9')) ||
((theChar>='a') && (theChar<='f')) ||
((theChar>='A') && (theChar<='F')) ||
(theChar == 0x09) ||
(theChar == 0x08))
return false;
else {
SysBeep(6);
return true;
}
}
return false;
}
Conduct_Goto_Dialog()
{
int item;
Str255 s;
Handle stringH;
Rect box;
int type;
dp = GetNewDialog( OwnedResourceID(GOTO_DIALOG), 0L, -1L );
Setup_Dialog();
do { /* until data valid */
for (;;) {
ModalDialog( Hex_Digit_Filter, &item );
if (item==CANCEL) {
DisposDialog(dp);
return 0;
}
if (item==OK) break;
}
GetDItem( dp, GOTOSTRING, &type, &stringH, &box );
GetIText( stringH, s );
} while (!validValue(s,&gotoPoint));
DisposDialog(dp);
return 1;
}
Setup_Dialog()
{
Str255 s;
int Stype;
Rect Sbox;
Handle Sitem;
GetDItem(dp, GOTOSTRING, &Stype, &Sitem, &Sbox);
Num_To_Hex(sBegin, s);
SetIText(Sitem, s);
SelIText(dp, GOTOSTRING, 0, s[0]);
}
static
validValue(s,v)
register char *s;
register long *v;
{
register int i;
*v = 0;
for (i=*s++; i>0; --i) {
*v *= 16;
*v += hexval(*s++);
}
if (*v<fileSize) return 1;
ErrorStr("\pAddress is beyond end of file.");
return 0;
}
static
hexval(c)
register char c;
{
if ((c>='0')&&(c<='9')) return c-'0';
if ((c>='a')&&(c<='f')) return c-'a'+10;
if ((c>='A')&&(c<='F')) return c-'a'+10;
DebugStr("\phexval failed");
}
extern char hexChar[];
Num_To_Hex(n,s)
register long n;
register char *s;
{
register int shift = 28;
register long m;
register char *count = s++;
register leading = true;
*count = 0;
for (shift=28; shift>=0; shift -=4) {
m = n >>shift;
if ((m>0) || ((m==0) && ((shift==0)||(!leading)))) {
leading = false;
(*count)++;
*s++ = hexChar[m&0x0000000F];
}
}
}